#include <iostream>
using namespace std;

template<class To, class From>
To ptr_cast(From from)
{
    To to = dynamic_cast<To>(from);
    return to? to: throw bad_cast();
}

class VBase
{
public:
    VBase()
        {
            
            cout << "VBase con" << endl;
        }
    virtual void fun()
        {
            cout << "Fun" << endl;
        }
};

class Derived: public virtual VBase
{
public:
    Derived()
        {
            cout << "Derived con" << endl;
        }
};

    
    
int main()
{
    //VBase * d = new VBase();
    VBase* d = new Derived();
    try{
        Derived* pd = ptr_cast<Derived*>(d);
    }

    catch(bad_cast)
    {
        cout << "Bad cast!!!" << endl;
        return -1;
    }
    cout << "Successfully cast!!!" << endl;
    
    return 0;
}

    
